import { cloneDeep } from 'lodash'
export default (data = {}) => {
  const {
    type,
    bots,
    meta = '{}',
    softwareId,
    appIds,
    integrations,
    botLimit,
    payUsers,
    freeUsers,
    ...rest
  } = cloneDeep(data)

  let threshold = meta === '' ? {} : JSON.parse(meta)
  let params = {
    ...rest,
    type
  }

  if (type === '13') {
    threshold.value = softwareId
    threshold.resourceType = String(type)
    threshold.resourceId = softwareId
  }

  if (type === '9') {
    threshold.value = integrations !== undefined ? String(integrations) : 'Infinity'
  }

  if (type === '4') {
    threshold.value = bots !== undefined ? String(bots) : 'Infinity'
  }

  if (type === '5') {
    threshold.value = payUsers !== undefined ? String(payUsers) : 'Infinity'
    threshold.freeUsers = freeUsers !== undefined ? String(freeUsers) : 'Infinity'
    threshold.resourceType = String(type)
    threshold.resourceId = appIds
    threshold.code = softwareId
  }

  if (type === '10') {
    threshold.value = botLimit !== undefined ? String(botLimit) : 'Infinity'
  }

  threshold.extra = data
  params.threshold = threshold

  return params
}
